#include ("/_includes/_layout.html")
#define css()
#end
#define script()
#end
#@layout("", "wxmall,点步科技", "Wxmall社区","wxmall")
#define content()
<div class="wrapper wrapper-content">
	<div class="ibox-content">
		<form id="__MarketcodeCodeactiveForm__" class="form-horizontal">
	        <input type="hidden" id="id" name="id" value="#(marketcodeCodeactive.id??)">
	        <div class="form-group">
                <label class="col-sm-2 control-label">申请单号</label>
                <div class="col-sm-8">
				   <input type="input" id="applicationId" name="applicationId" class="form-control" value="#(marketcodeApply.applicationId??)" placeholder="" readonly="readonly"/>
                </div>
	        </div>
	        <div class="form-group">
                <label class="col-sm-2 control-label"><span class="requirespan">*</span>活动名称</label>
                <div class="col-sm-8">
				   <input type="input" id="activityName" name="activityName" class="form-control" value="#(marketcodeCodeactive.activityName??)" placeholder=""/>
                </div>
	        </div>
	        <div class="form-group">
                <label class="col-sm-2 control-label"><span class="requirespan">*</span>商品品牌</label>
                <div class="col-sm-8">
				   <input type="input" id="productBrand" name="productBrand" class="form-control" value="#(marketcodeCodeactive.productBrand??)" placeholder=""/>
                </div>
	        </div>
	        <div class="form-group">
                <label class="col-sm-2 control-label"><span class="requirespan">*</span>商品标题</label>
                <div class="col-sm-8">
				   <input type="input" id="productTitle" name="productTitle" class="form-control" value="#(marketcodeCodeactive.productTitle??)" placeholder=""/>
                </div>
	        </div>
	        <div class="form-group">
                <label class="col-sm-2 control-label"><span class="requirespan">*</span>商品条码</label>
                <div class="col-sm-8">
				   <input type="input" id="productCode" name="productCode" class="form-control" value="#(marketcodeCodeactive.productCode??)" placeholder=""/>
                </div>
	        </div>
	        <div class="form-group">
                <label class="col-sm-2 control-label"><span class="requirespan">*</span>小程序appid</label>
                <div class="col-sm-8">
                	<select id="wxaAppid" name="wxaAppid" class="form-control">
                		<option value="">请选择小程序</option>
                		#for(weapp :weapps)
                		<option id="#(weapp.id??)" value="#(weapp.appId??)" #if(marketcodeCodeactive.wxaAppid?? && marketcodeCodeactive.wxaAppid == weapp.appId) selected="selected" #end>#(weapp.nickName??)</option>
                		#end
                	</select>
                   <div id="templateInfoDiv">
                   #if(weappTemplate??)
                   <span class="help-block m-b-none">使用小程序模板<font color="red">[#(weappTemplate.templateName??)]</font></span>
                   #end
                   </div>
                </div>
	        </div>
	        <div class="form-group">
                <label class="col-sm-2 control-label"><span class="requirespan">*</span>小程序path</label>
                <div class="col-sm-8">
				   <input type="input" id="wxaPath" name="wxaPath" class="form-control" value="#(marketcodeCodeactive.wxaPath??)" placeholder=""/>
                </div>
	        </div>
	        <div class="form-group">
                <label class="col-sm-2 control-label">小程序版本</label>
                <div class="col-sm-8">
				   <select id="wxaType" name="wxaType" class="form-control">
				   		<option value="0">正式版</option>
				   		<option value="2">体验版</option>
				   		<option value="1">开发版</option>
				   </select>
                </div>
	        </div>
	        <!-- <div class="form-group">
                <label class="col-sm-2 control-label">激活码段的起始位</label>
                <div class="col-sm-8">
				   <input type="input" id="codeStart" name="codeStart" class="form-control" value="#(marketcodeCodeactive.codeStart??)" placeholder="" onkeyup="this.value=this.value.replace(/\D/g,'')"/>
                </div>
	        </div>
	        <div class="form-group">
                <label class="col-sm-2 control-label">激活码段的结束位</label>
                <div class="col-sm-8">
				   <input type="input" id="codeEnd" name="codeEnd" class="form-control" value="#(marketcodeCodeactive.codeEnd??)" placeholder="" onkeyup="this.value=this.value.replace(/\D/g,'')"/>
                </div>
	        </div> -->
	        <div class="form-group">
	            <div class="panel-footer" align="center">
			        <button type="submit" class="btn btn-success btn-sm">提 交</button>
			        <a href="#(webctx)/marketcode/marketcodecodeactive" class="btn btn-default btn-sm">取   消</a>
				</div>
	        </div>
		</form>
	</div>
</div>
<script type="text/html" id="templateInfoDiv_tpl">
<span class="help-block m-b-none">使用小程序模板<font color="red">[{{templateName}}]</font></span>
</script>
<script type="text/javascript">
var icon = "<i class='fa fa-times-circle'></i> ";
$("#__MarketcodeCodeactiveForm__").validate({
	ignore: "",
    submitHandler:function() {
    	$("#__MarketcodeCodeactiveForm__").mask("正在处理中...");
    	var params = $("#__MarketcodeCodeactiveForm__").serializeJSON();
    	obz.ajaxJson(obz.ctx+"/marketcode/marketcodecodeactive/save", params, function(json) {
    		$("#__MarketcodeCodeactiveForm__").unmask();
    		if(json.state == "ok" || json.code == 200){
    			obz.msg('操作成功', function(){
					location.href="#(webctx)/marketcode/marketcodecodeactive";
				});	
			}
		});
    },
    rules: {
    	applicationId: "required",
    	activityName: "required",
    	productBrand: "required",
    	productTitle: "required",
    	productCode: "required",
    	wxaAppid: "required",
    	wxaPath: "required",
    },
    messages: {
    	applicationId: icon + "请输入申请单号", 
    	activityName: icon + "请输入活动名称", 
    	productBrand: icon + "请输入商品品牌", 
    	productTitle: icon + "请输入商品标题", 
    	productCode: icon + "请输入商品条码", 
    	wxaAppid: icon + "请选择小程序", 
    	wxaPath: icon + "请输入小程序的path", 
    }
});

$("#wxaAppid").change(function(){
	var id = $(this).find("option:checked").attr("id");
	obz.ajaxJson("#(webctx)/marketcode/marketcodecodeactive/checkWeapp", {id:id}, function(resp){
		if(resp.state =="fail"){
			$("#wxaAppid").val("");
			/* obz.showMessage("该小程序未设置模板，现在去设置小程序模板吗?", function(){
				location.href="#(webctx)/weapp/set/?weappId=" + id;
			}); */
		}else{
			//根据对应的模板加载小程序激活规则
			if(resp.data){
				$("#templateInfoDiv").html(template("templateInfoDiv_tpl", resp.data));				
			}else{
				$("#templateInfoDiv").html('<span class="help-block m-b-none"><font color="red">该小程序未配置模板，</font><a href="#(webctx)/weapp/set/?weappId='+id+'">现在去配置</a></span>');
			}
		}
	});
})
</script>
#end